<?php
/**
 * 博客分类
 * @author zelome@163.com
 * $Id: index.php 10 2011-02-23 07:01:48Z sbnnest@gmail.com $
 */

require_once('../common.inc.php');

class categorylist extends Action
{
	/**
	 * 获取博客分类列表
	 */
	function doDefault()
	{
		$page = $this->app->page();
		$page->params['template'] = 'content/categorylist.tpl';
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_serial');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		$db_r->addField('article_category_createtime');
		$db_r->addField('article_category_modifytime');
		
		$rs = $db_r->getArray();
		$page->value('articleCategoryList',$rs);
		
		$page->output();
	}
	
	/**
	 * 添加博客分类
	 */
	function doAdd(){
		$categoryname = trim($_POST['categoryname']);
		$page = $this->app->page();
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		$db_r->addField('article_category_createtime');
		$db_r->addField('article_category_modifytime');
		$db_r->addField('article_category_entry');
		
		array(array('id'=>1));
		$db_r->insert(array('article_category_name' => $categoryname ,'article_category_createtime' => date('Y-m-d H:i:s'),'article_category_modifytime'=>date('Y-m-d H:i:s')));
		
		$page = $this->app->page();
		$page->params['template'] = 'content/categoryadd.tpl';
		$page->output();
	}
	
	/**
	 * 跳转到博客分类列表
	 */
	function doAddpage(){
		$page = $this->app->page();
		$page->params['template'] = 'content/categoryadd.tpl';
		$page->output();
	}
	
	/**
	 * 删除博客分类
	 */
	function doDelete(){
		$article_category_id = $_GET['article_category_id'];
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addWhere('article_category_id',$article_category_id);
		$db_r->delete();
		
		$page = $this->app->page();
		$page->params['template'] = 'content/categorylist.tpl';
		
		
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		$db_r->addField('article_category_createtime');
		$db_r->addField('article_category_modifytime');
		$rs = $db_r->getArray();
		$page->value('articleCategoryList',$rs);
		
		$page->output();
	}
	
	/**
	 * 跳转到修改博客分类页面
	 */
	function doModifypage(){
		$page = $this->app->page ();
		$page->params ['template'] = 'content/categorymodify.tpl';
		
		$article_category_id = trim ( $_GET ['article_category_id'] );
		$page = $this->app->page ();
		$db_r = $this->app->orm()->query();
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		
		$db_r->addWhere ( 'article_category_id', $article_category_id );
		$result = $db_r->getRow ();
		$page->value ( 'article_category_id', $article_category_id );
		$page->value ( 'tb_article_category', $article_category_id );
		$page->value ( 'categoryname', $result ['article_category_name'] );
		$page->output ();
	}
	
	/**
	 * 修改博客分类
	 */
	function doModify(){
		$page = $this->app->page ();
		$db_r = $this->app->orm ()->query ();
		$page->params ['template'] = 'content/categorymodify.tpl';
		
		$article_category_id = trim($_POST['article_category_id']);
		$categoryname = trim($_POST['categoryname']);
		$db_r->addTable('tb_article_category');
		$db_r->addField('article_category_id');
		$db_r->addField('article_category_count');
		$db_r->addField('article_category_name');
		$db_r->addField('article_category_createtime');
		$db_r->addField('article_category_modifytime');
		$db_r->addField('article_category_entry');
		
		$db_r->addWhere ( 'article_category_id', $article_category_id );
		$db_r->update (array('article_category_name' => $categoryname ,'article_category_modifytime'=>date('Y-m-d H:i:s')));
		$page->output ();
	}
	
}
											
$app->run();

?>
